package data;

import java.sql.*;

public class GridSample extends DataElement
{
    public int grid_id;
    public java.util.Date time;
    public double sun_theta;
    public double sun_phi;
    
    public GridSample( DataFactory factory )
    {
	super( factory );
    }
    
    protected String valuesString()
    {
	String convertedTime = "'" + (new java.sql.Timestamp( time.getTime() )).toString() + "'";
	return "" + grid_id + ", " +
	    convertedTime + ", " +
	    sun_theta + ", " +
	    sun_phi;
    }
    
    protected void _loadFrom( ResultSet rs ) throws SQLException
    {
	grid_id = rs.getInt( "grid_id" );
	time = new Date( rs.getTimestamp( "time" ).getTime() );
	sun_theta = rs.getDouble( "sun_theta" );
	sun_phi = rs.getDouble( "sun_phi" );
    }
    
    protected String _insert()
    {
	return "(grid_id, time, sun_theta, sun_phi) values (" + valuesString() + ")";
    }
    
    protected String _update()
    {
	String convertedTime = "'" + (new java.sql.Timestamp( time.getTime() )).toString() + "'";
	return "grid_id=" + grid_id +
	    ", time=" + convertedTime +
	    ", sun_theta=" + sun_theta + 
	    ", sun_phi=" + sun_phi;
    }

    Grid getGrid()
    {
	return getFactory().getDatabase().getGridFactory().lookup( grid_id );
    }
}
